#include <netfwd.h>
#include <rbtree.h>

#define MAX_CONN_ARY	1000

const char * ip1 = "10.2.136.92";
const char * ip2 = "172.25.34.159";

std::allocator<std::string> rb_allocate;

void test_leak( const std::string & str )
{
	void * addr = rb_allocate.allocate(1);
	std::string * str1 = new(addr)std::string;	
	*str1 = str;
	(*str1).~basic_string();
	rb_allocate.deallocate( str1, sizeof( std::string ) );
	return;
}

int main()
{
	typedef RBTree< std::string, int > RouteMap_t; 
	RouteMap_t rmap;
	
	rmap.insert( "1", 1 );
	rmap.insert( "2", 2 );
	rmap.insert( "3", 3 );
	
	//test_leak( "23" );
	
	for( RouteMap_t::iterator i = rmap.begin(); i != rmap.end(); ++i )
		std::cout << "key[" << i.first() << "] value[" << i.second() << "]" << std::endl;
		
	std::cout << "map size=" << rmap.size() << std::endl;
	
#if 0	
	for( RouteMap_t::iterator i = rmap.begin(); i != rmap.end(); ++i )
		if( 0 == i.first().compare("1") || 
			0 == i.first().compare("2") )
			rmap.erase( i );
#endif
	rmap.erase( "1" );
	rmap.erase( "1" );
	rmap.erase( "2" );
	
	std::cout << "map size=" << rmap.size() << std::endl;
	
	for( RouteMap_t::iterator i = rmap.begin(); i != rmap.end(); ++i )
		std::cout << "key[" << i.first() << "] value[" << i.second() << "]" << std::endl;
		
	rmap.clear();
	
	typedef RBTree< int, int > NumMap_t;
	NumMap_t nmap;

	nmap.insert( 1, 1 );
	nmap.insert( 2, 2 );
	nmap.insert( 3, 3 );

	for( NumMap_t::iterator i = nmap.begin(); i != nmap.end(); ++i )
		std::cout << "aaa key[" << i.first() << "] value[" << i.second() << "]" << std::endl;	
	
	nmap.erase( 1 );
	
	for( NumMap_t::iterator i = nmap.begin(); i != nmap.end(); ++i )
		std::cout << "bbb key[" << i.first() << "] value[" << i.second() << "]" << std::endl;	

	nmap.clear();
    //rmap.erase( ip_addr1 );
	return 0;
}
